import request from '@/config/axios'

export interface EvalSupervisionRecordVO {
  id?: number
  planId: number
  supervisorId: number
  supervisionDate: string
  supervisionType: string
  supervisionContent: string
  supervisionResult: string
  supervisionScore?: number
  supervisionStatus: number
  supervisionComments?: string
  createTime?: Date
}

export interface EvalSupervisionRecordPageReqVO extends PageParam {
  planId?: number
  supervisorId?: number
  supervisionType?: string
  supervisionStatus?: number
  supervisionDate?: string[]
  createTime?: Date[]
}

export interface EvalSupervisionReportVO {
  planId: number
  planName: string
  totalSupervisionCount: number
  passedCount: number
  failedCount: number
  averageScore: number
  supervisionRate: number
  lastSupervisionDate?: string
}

// 查询督导检查记录分页
export const getSupervisionRecordPage = (params: EvalSupervisionRecordPageReqVO) => {
  return request.get({ url: '/eval/supervision-record/page', params })
}

// 查询督导检查记录详情
export const getSupervisionRecord = (id: number) => {
  return request.get({ url: '/eval/supervision-record/get?id=' + id })
}

// 新增督导检查记录
export const createSupervisionRecord = (data: EvalSupervisionRecordVO) => {
  return request.post({ url: '/eval/supervision-record/create', data })
}

// 修改督导检查记录
export const updateSupervisionRecord = (data: EvalSupervisionRecordVO) => {
  return request.put({ url: '/eval/supervision-record/update', data })
}

// 删除督导检查记录
export const deleteSupervisionRecord = (id: number) => {
  return request.delete({ url: '/eval/supervision-record/delete?id=' + id })
}

// 导出督导检查记录
export const exportSupervisionRecord = (params: EvalSupervisionRecordPageReqVO) => {
  return request.download({ url: '/eval/supervision-record/export-excel', params })
}

// 根据计划ID获得督导检查记录列表
export const getSupervisionRecordListByPlanId = (planId: number) => {
  return request.get({ url: '/eval/supervision-record/list-by-plan?planId=' + planId })
}

// 根据督导员ID获得督导检查记录列表
export const getSupervisionRecordListBySupervisorId = (supervisorId: number) => {
  return request.get({ url: '/eval/supervision-record/list-by-supervisor?supervisorId=' + supervisorId })
}

// 根据督导类型获得督导检查记录列表
export const getSupervisionRecordListByType = (supervisionType: string) => {
  return request.get({ url: '/eval/supervision-record/list-by-type?supervisionType=' + supervisionType })
}

// 根据状态获得督导检查记录列表
export const getSupervisionRecordListByStatus = (supervisionStatus: number) => {
  return request.get({ url: '/eval/supervision-record/list-by-status?supervisionStatus=' + supervisionStatus })
}

// 获取督导统计信息
export const getSupervisionStatistics = (): Promise<any> => {
  return request.get({ url: '/eval/supervision-record/statistics' })
}

// 获取督导报表
export const getSupervisionReport = (planId?: number): Promise<EvalSupervisionReportVO[]> => {
  const params = planId ? { planId } : {}
  return request.get({ url: '/eval/supervision-record/report', params })
}

// 提交督导检查
export const submitSupervisionRecord = (id: number) => {
  return request.put({ url: '/eval/supervision-record/submit?id=' + id })
}

// 审核督导检查
export const auditSupervisionRecord = (id: number, auditResult: boolean, auditComments?: string) => {
  return request.put({ url: '/eval/supervision-record/audit', data: { id, auditResult, auditComments } })
}

// 获取督导检查模板
export const getSupervisionTemplate = (supervisionType: string) => {
  return request.get({ url: '/eval/supervision-record/template?supervisionType=' + supervisionType })
}

// 生成督导检查报告
export const generateSupervisionReport = (planId: number) => {
  return request.post({ url: '/eval/supervision-record/generate-report?planId=' + planId })
}
